import {_decorator, Component, Node, CCInteger} from 'cc';

const {ccclass, property} = _decorator;

@ccclass('BGController')
export class BGController extends Component {
    /**
     * 速度
     */
    @property(CCInteger)
    speed: number = 4;

    /**
     * 宽度
     */
    @property(CCInteger)
    width: number = 288;

    start() {

    }

    update(deltaTime: number) {
        for (let node of this.node.children) {
            // 移动
            node.setPosition(node.position.x - this.speed * deltaTime, node.position.y);
            // 当对象移出屏幕时
            if (node.position.x < -this.width) {
                // 重新设置位置
                node.setPosition(node.position.x + this.width * 2, node.position.y);
            }
        }
    }
}

